package com.lili.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lili.controller.request.XasAdListRequest;
import com.lili.controller.request.XasAdPositionListRequest;
import com.lili.po.XasAdList;
import com.lili.po.XasAdPositionList;
import com.lili.service.XasAdService;
import com.lili.vo.MyPage;
import com.lili.vo.ResponseResult;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("ad")
public class XasAdController {
    @Autowired
    XasAdService xasAdService;

    @RequestMapping("selectXasAdList")
    public ResponseResult selectXasAdList(@RequestBody XasAdListRequest xasAdListRequest){
        ResponseResult responseResult = new ResponseResult();
        MyPage myPage = new MyPage();
        BeanUtils.copyProperties(xasAdListRequest, myPage);
        IPage<XasAdList> iPage = xasAdService.selectXasAdList(xasAdListRequest);
        myPage.setTotal(iPage.getTotal());
        myPage.setRecords(iPage.getRecords());
        responseResult.setData(myPage);
        return responseResult;
    }

    @RequestMapping("selectAllXasAdList")
    public ResponseResult selectAllXasAdList(){
        ResponseResult responseResult = new ResponseResult();
        List<XasAdList> selectXasAdList = xasAdService.selectAllXasAdList();
        responseResult.setData(selectXasAdList);
        return responseResult;
    }


    @RequestMapping("addXasAdList")
    public ResponseResult addXasAdList(@RequestBody XasAdList xasAdList) {
        xasAdService.addXasAdList(xasAdList);
        return new ResponseResult();
    }

    @RequestMapping("updateXasAdList")
    public ResponseResult updateXasAdList(@RequestBody XasAdList xasAdList) {
        xasAdService.updateXasAdList(xasAdList);
        return new ResponseResult();
    }

    @RequestMapping("delXasAdList")
    public ResponseResult delXasAdList(@RequestBody XasAdList xasAdList) {
        xasAdService.delXasAdList(xasAdList.getId());
        return new ResponseResult();
    }



    @RequestMapping("selectXasAdPositionList")
    public ResponseResult selectXasAdPositionList(@RequestBody XasAdPositionListRequest xasAdPositionListRequest){
        ResponseResult responseResult = new ResponseResult();
        MyPage myPage = new MyPage();
        BeanUtils.copyProperties(xasAdPositionListRequest, myPage);
        IPage<XasAdPositionList> iPage = xasAdService.selectXasAdPositionList(xasAdPositionListRequest);
        myPage.setTotal(iPage.getTotal());
        myPage.setRecords(iPage.getRecords());
        responseResult.setData(myPage);
        return responseResult;
    }

    @RequestMapping("selectAllXasAdPositionList")
    public ResponseResult selectAllXasAdPositionList(){
        ResponseResult responseResult = new ResponseResult();
        List<XasAdPositionList> xasAdPositionLists = xasAdService.selectAllXasAdPositionList();
        responseResult.setData(xasAdPositionLists);
        return responseResult;
    }


    @RequestMapping("addXasAdPositionList")
    public ResponseResult addXasAdPositionList(@RequestBody XasAdPositionList xasAdPositionList) {
        xasAdService.addXasAdPositionList(xasAdPositionList);
        return new ResponseResult();
    }

    @RequestMapping("updateXasAdPositionList")
    public ResponseResult updateXasAdPositionList(@RequestBody XasAdPositionList xasAdPositionList) {
        xasAdService.updateXasAdPositionList(xasAdPositionList);
        return new ResponseResult();
    }

    @RequestMapping("delXasAdPositionList")
    public ResponseResult delXasAdPositionList(@RequestBody XasAdPositionList xasAdPositionList) {
        xasAdService.delXasAdPositionList(xasAdPositionList.getId());
        return new ResponseResult();
    }
}
